package util2;

import java.util.concurrent.Exchanger;

public class ExchangerUtil {

	public static void main(String[] args) {
		Exchanger<String> exchanger = new Exchanger();
		new Thread(()->{
			try {
				System.out.println("张飞：驾....驾....驾....驾....");
				Thread.sleep(3000);
				String zf = exchanger.exchange("大哥..我回来了...");
				System.out.println("刘备说：" + zf);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}).start();
		new Thread(()->{
			try {
				System.out.println("到处观望......");
				Thread.sleep(1000);
				String lb = exchanger.exchange("三弟你终于回来了...");
				System.out.println("张飞说：" + lb);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}).start();
		
		
	}

}
